package leetcode.code1626;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int bestTeamScore(int[] scores, int[] ages) {
		int len = scores.length;
		Integer[] idx = new Integer[len];
		for (int i = 0; i < len; i++) {
			idx[i] = i;
		}
		Arrays.sort(idx, (a, b) -> ages[a] == ages[b] ? scores[a] - scores[b] : ages[a] - ages[b]);
		int[] dp = new int[len];
		int ans = 0;
		for (int i = 0; i < dp.length; i++) {
			int ci = idx[i];
			dp[i] = scores[ci];
			for (int j = 0; j < i; j++) {
				int cj = idx[j];
				if (scores[ci] >= scores[cj]) {
					dp[i] = Math.max(dp[i], dp[j] + scores[ci]);
				}
			}
			ans = Math.max(ans, dp[i]);
		}
		return ans;
	}
	

	@Override
	public void debug4() {
		int[] arr = H.str2array3("[319776,611683,835240,602298,430007,574,142444,858606,734364,896074]");
		H.print(arr);
		Arrays.sort(arr);
		H.print(arr);
		H.compare(27, this.bestTeamScore(H.str2array3("[9,2,8,8,2]"), H.str2array3("[4,1,3,3,5]")));
		H.compare(5431066, this.bestTeamScore(H.str2array3("[319776,611683,835240,602298,430007,574,142444,858606,734364,896074]"), H.str2array3("[1,1,1,1,1,1,1,1,1,1]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
